package demo1;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Demo {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        //需求：实例化一个user并调用sayHello方法
        //原始的创建方式
        User user=new User();
        user.sayHello();
        //利用反射机制创建对象
        Class cls= Class.forName("demo1.User");
        User user1=(User) cls.newInstance();
        user1.sayHello();
        //使用Spring容器
        AnnotationConfigApplicationContext context
                =new AnnotationConfigApplicationContext("demo1");
        User user2 = context.getBean(User.class);
        user2.sayHello();
    }
}
